﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>条码档案信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>
    <script type="text/html" id="barDemo">
        <a title="确认选择" href="javascript:;" lay-event="sure"><i class="layui-icon">&#xe679;</i></a>
    </script>

    <script type="text/html" id="barT">
        <a title="数据明细" href="javascript:;" lay-event="view"><i class="layui-icon">&#xe647;</i></a>
    </script>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <div class="layui-inline layui-show-xs-block">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" id="fhCode" name="fhCode" placeholder="选择发货单" class="layui-input" onclick="outOrder()" />
                                <input type="hidden" id="fhId" name="fhId"  />
                            </div>
                        </div>
                    </div>

                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                            <input type="hidden" name="svalue" id="svalue" />
                            <input type="hidden" name="rowId" id="rowId" />
                            <input type="hidden" name="outOrderCode" id="outOrderCode" />
                        </form>
                    </div>
             
                    <div class="layui-card-body layui-table-body layui-table-main">
                        <table class="layui-hide" id="orList" lay-filter="orList"></table>
                    </div>


                    <div class="layui-card-body ">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" id="tempCode" name="tempCode" placeholder="临时编码" class="layui-input">
                        </div>

                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-filter="btnQuery" id="btnQuery" type="button" onclick="loadTempData()"><i class="layui-icon">&#xe615;</i>查询</button>
                            <button class="layui-btn" lay-filter="sreach" id="userSearch" type="button" onclick="sureChoose()"><i class="layui-icon">&#xe605;</i>确认选择</button>
                            <button class="layui-btn" lay-filter="btnSubmit" id="btnSubmit" type="button" onclick="saveTemp()"><i class="layui-icon">&#xe672;</i>出库提交</button>
                        </div>
                    </div>
                    <div class="layui-card-body layui-table-body layui-table-main">
                        <table class="layui-hide" id="barList" lay-filter="barList"></table>
                    </div>
                    <div class="layui-card-body layui-table-body layui-table-main">
                        <table class="layui-hide" id="lslist" lay-filter="lslist"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>

<script>
    /**
    在库条码
    **/
    function loadData(condition) {
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#barList'
            , cols: [[ //标题栏
              { type: 'checkbox' }
            , { field: 'barCode', title: '条码', width: 130 }
            , { field: 'proCode', title: '存货编码', width: 110, }
            , { field: 'proName', title: '存货名称', width: 150 }
            , { field: 'spec', title: '规格型号', width: 130 }
            , { field: 'c_tssx', title: '特殊属性', width: 90, }
            , { field: 'c_mishu', title: '米数/个数', width: 100 }
            , { field: 'c_gongjin', title: '公斤数', width: 100 }
            , { field: 'gxName', title: '工序', width: 90 }
            , { field: 'barStatusName', title: '条码状态', width: 90 }
            , { field: 'relationBar', title: '关联条码', width: 120 }
            , { field: 'pusers', title: '生产人员', width: 120 }
            ]], done: function (res, curr, count) {

            }
            , url: "../Bar/GetDataList?dataType=barIn&condition=" + condition
            , skin: 'row' //表格风格
            , even: true
            , page: true //是否显示分页
            , limits: [15, 25, 40]
            , limit: 15 //每页默认显示的数量
            });
            //监听工具条

            table.on('checkbox(barList)', function (obj) {
                var data = obj.data;
                //为父窗口input赋值
                $("#svalue").val("");
                var checkStatus = table.checkStatus('barList');
                var codes = "";
                for (var i = 0; i < checkStatus.data.length; i++) {
                    codes += checkStatus.data[i].barCode + ",";
                }
                $("#svalue").val(codes.substr(0, codes.length - 1));

            });

        });
    }
    /**
    加载单据数据
    **/
    function loadOrderList() {
        var tempCode = $("input[ name='fhId']").val();
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#orList'
            , cols: [[ //标题栏
              { field: 'cInvCode', title: '存货编码', width: 100 }
            , { field: 'cInvName', title: '存货名称', width: 120, }
            , { field: 'cInvStd', title: '规格货号', width: 110, }
            , { field: 'cFree7', title: '特殊属性', width: 110, }
            , { field: 'cWhName', title: '所属仓库', width: 110, }
            , { field: 'autoid', title: 'autoid', width: 90, }
            , { field: 'right', title: '操作', toolbar: '#barDemo', width: 120, fixed: 'right' }
            ]], done: function (res, curr, count) {
                $("[data-field='autoid']").css('display', 'none');//隐藏列
            }
            , url: "../Bar/GetDataList?dataType=olt&condition=" + tempCode
            , skin: 'row' //表格风格
            , even: true
            , page: false //是否显示分页
            });
            //监听工具条
            table.on('tool(orList)', function (obj) {
                var data = obj.data;
                if (obj.event == 'sure') {
                    var condate = new Object();
                    condate.proCode = data.cInvCode;
                    condate.spec = data.cInvStd;
                    condate.wareHouse = data.cWhCode;
                    condate.c_tssx = data.cFree7;
                    var dstr = JSON.stringify(condate);
                    //var dstr = data.cInvCode + "," + data.cInvStd + "," + data.cWhCode + "," + data.autoid;
                    $("input[name='rowId']").val(data.autoid);
                    loadData(dstr);
                }
            });

        });
    }

    $(function () {


    })
    layui.use(['laydate'], function () {
        var $ = layui.$;
        var laydate = layui.laydate;
        var nowTime = new Date().valueOf();
        var max = null;
        var start = laydate.render({
            elem: '#happenDate',
            trigger: 'click',
            type: 'date',
            format: 'yyyy-MM-dd',
            btns: ['clear', 'confirm'],
            done: function (value, date) {

            }
        });
    })

    /**
    确认选择
    **/
    function sureChoose() {
        var tempCode = $("input[ name='tempCode']").val();
        if (tempCode == "") {
            layer.msg("请先输入临时编码"); return;
        }
        var param = new Object();
        param.tempCode = tempCode;
        param.outOrderCode = $("#fhCode").val();
        var value = $("#svalue").val();
        //$("#outOrderCode").val($("#fhCode").val());//发货单单号
        if (value == "") {
            layer.msg("没有选择任何数据"); return;
        } else {
            var datas = JSON.stringify(FormToJson("qForm"));
            var condition = JSON.stringify(param);
            $.ajax({
                url: "../Bar/ChooseOutWareTemp",
                type: "post",
                data: { datas: datas, condition: condition, },
                success: function (rsl) {
                    if (rsl.Result) {
                        layer.msg("选码成功");
                        loadData();
                        loadTempData();
                    } else {
                        layer.msg(rsl.Message);
                    }
                }
            });
        }

    }
    /**
    发货单
    **/
    function outOrder() {
        var url = "../Bar/OutOrder";
        OpenPage("U8发货单", url);
    }
    /**
    提交扫码入库
    **/
    function saveTemp() {
        var tempCode = "0"+"-"+$("input[ name='tempCode']").val();
        if (tempCode == "") {
            layer.msg("请先输入临时编码"); return;
        }
        $.ajax({
            url: "../Bar/SaveInOutData",
            type: "post",
            data: { tempCode: tempCode },
            success: function (rsl) {
                if (rsl.Result) {
                    layer.msg("选码出库成功");
                    loadData();
                    loadTempData();
                } else {
                    layer.msg(rsl.Message);
                }
            }
        });
    }
    var cData=""
    function getChildPar(pars) {
        cDatas = pars;
        $("input[ name='fhCode']").val(cDatas.cDLCode);
        $("input[ name='fhId']").val(cDatas.dlid);
        loadOrderList();
    }


    /**
   加载临时数据
   **/
    function loadTempData() {
        var tempCode = 0 + "-" + $("input[ name='tempCode']").val();
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#lslist'
            , cols: [[ //标题栏
              { field: 'tempCode', title: '临时编码', width: 100 }
            , { field: 'proCode', title: '存货编码', width: 110, }
            , { field: 'proName', title: '存货名称', width: 110, }
            , { field: 'spec', title: '规格货号', width: 110, }
            , { field: 'c_tssx', title: '特殊属性', width: 110, }
            , { field: 'gongjin', title: '主计量数', width: 100 }
            , { field: 'mishu', title: '辅助计量数', width: 100 }
            , { field: 'barCount', title: '件数', width: 100, }
            , { field: 'id', title: '选择条码', width: 110, }
            , { field: 'right', title: '操作', toolbar: '#barT', width: 90, fixed: 'right' }
            ]], done: function (res, curr, count) {
                $("[data-field='id']").css('display', 'none');//隐藏列
            }
            , height: 350
            , url: "../Bar/GetDataList?dataType=tsb&condition=" + tempCode
            , skin: 'row' //表格风格
            , even: true
            , page: false //是否显示分页
            });
            //监听工具条
            table.on('tool(lslist)', function (obj) {
                var data = obj.data;
                if (obj.event == 'view') {
                    url = "../Bar/TempBars?tempCode=" + data.tempCode + "&proCode=" + data.proCode + "&spec=" + data.spec;
                    OpenPage("扫码明细(" + data.tempCode + ")", url);
                    loadTempData();
                }


            });

        });
    }
</script>